import BasePanel from "./BasePanel";

const {ccclass, property} = cc._decorator;

@ccclass
export default class MenuManager extends cc.Component {
    
    private menuPanel:cc.Node;

    onLoad(){       
        if(!cc.game.isPersistRootNode(this.node)){
            cc.game.addPersistRootNode(this.node);
        }     
        this.menuPanel = this.node.getChildByName("MenuPanel");

        
        var manager = cc.director.getCollisionManager();
        manager.enabled = true;
        manager.enabledDebugDraw = true;
        //manager.enabledDrawBoundingBox=true;
         
        
        


        this.node.active = false; 
                
        //监听子菜单点击事件
        this.node.on("MenuClicked",this.OpenMenuPanel,this);
    }

    /**
     * 打开菜单面板
     */
    OpenMenuPanel(event:cc.Event.EventCustom){
        //暂停当前主逻辑
        cc.director.pause();        
        var name = event.target.name;
        cc.log(name);

        var panel = this.menuPanel.getChildByName(name+"Panel");
        if(panel){
            panel.getComponent(BasePanel).show();
        }        
    }
}
